import React, { createContext, useContext, useState, ReactNode } from 'react';

// 定义主题类型
export type ThemeType = 'ink' | 'cartoon';

// 定义主题上下文类型
interface ThemeContextType {
  theme: ThemeType;
  toggleTheme: () => void;
}

// 创建主题上下文
const ThemeContext = createContext<ThemeContextType | undefined>(undefined);

// 主题提供者组件
interface ThemeProviderProps {
  children: ReactNode;
}

export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
  const [theme, setTheme] = useState<ThemeType>('ink'); // 默认使用水墨风格

  const toggleTheme = () => {
    setTheme(prev => prev === 'ink' ? 'cartoon' : 'ink');
  };

  return (
    <ThemeContext.Provider value={{ theme, toggleTheme }}>
      {children}
    </ThemeContext.Provider>
  );
};

// 创建自定义Hook，方便使用主题
export const useTheme = (): ThemeContextType => {
  const context = useContext(ThemeContext);
  if (context === undefined) {
    throw new Error('useTheme must be used within a ThemeProvider');
  }
  return context;
}; 